%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This code generates a parameter structure for the case of EIS ~= 1
% All values are in quarterly values
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [I , J] = param_EIS(nu , phi , psi)

I = param_Data;

%% Preference parameters
I.psi = psi;                                    %EIS coefficient
I.theta = (1-I.gamma)/(1-1/I.psi); 

%% Belief updating
I.nu = nu;                                   %Learning gain
I.phi = phi;                                   %(Inverse)Prior informativeness
I.tnu = I.phi * I.nu;   

%% Check Bound
if log(I.delta) + (1 - 1/I.psi) * ( I.mu + 0.5 * (1 - I.gamma) * (1 + I.tnu) * I.sigma^2/(1 - I.phi)^2 ) >= 0 || I.tnu >= I.nu && I.nu~=0
    error('Parameter Constraints Violated !!!')
end

%% Log-linearization
Res_WC = compute_wc_LL(I);
Res_PD = compute_pd_LL(I , Res_WC);
J = calculateAcoeff_EIS(I);

%% Log SDF coefficients
I.tmu_m_s = log(I.delta) - (1 - I.phi) * I.mu/I.psi - 0.5 * (1 - I.gamma) * (1/I.psi - I.gamma) * (1 + J.kappa_1 * I.phi * I.nu/(1 - (1 - I.nu + I.phi * I.nu) * J.kappa_1))^2 * (1 + I.phi * I.nu) * I.sigma^2;
I.xi_s = ( 1/I.psi - (1/I.psi - I.gamma) * (1 + J.kappa_1 * I.phi * I.nu/(1 - (1 - I.nu + I.phi * I.nu) * J.kappa_1)) ) * sqrt(1 + I.phi * I.nu);

%% Conditional Sharpe ratio

% Coefficient of \tmu_t in the expression for the conditional Sharpe ratio 
% i.e. Conditional Sharpe ratio = I.sharpeconst + I.sharpecoeff * \tmu_t
% K < 0 or I.sharpe > 0 then conditional sharpe ratio is pro-cyclical.
I.K = 1/I.psi + J.Ad_1 - (1 - I.nu) * J.Ad_1 * J.kappad_1; 

I.sharpecoeff = -I.phi * I.K/sqrt(I.K^2 * I.sigma^2 + (J.kappad_1 * J.Ad_2 + 1)^2 * I.sigma_d^2);

I.sharpeconst = ( I.K * I.mu + (J.kappad_1 - 1) * J.Ad_0 + J.kappad_0 + (J.kappad_1 * J.Ad_2 + 1) * I.alpha * I.mu_dc ...
              +   log(I.delta) - 0.5 * (1 - I.gamma) * (1/I.psi - I.gamma) * (1 + J.kappa_1 * I.phi * I.nu/(1 - (1 - I.nu + I.phi * I.nu) * J.kappa_1))^2 * (1 + I.phi * I.nu) * I.sigma^2 ...
              +   0.5 * ((1/I.psi - I.gamma) * (1 + J.kappa_1 * I.phi * I.nu/(1 - (1 - I.nu + I.phi * I.nu) * J.kappa_1)) - 1/I.psi)^2 * (1 + I.phi * I.nu) * I.sigma^2 ) ...
              /   sqrt(I.K^2 * I.sigma^2 + (J.kappad_1 * J.Ad_2 + 1)^2 * I.sigma_d^2);
          
end